package com.macro.mall.common.api;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ReturnObject<T> {

    /**
     *  true 成功 false 失败
     */
    private Boolean flag = true;

    /**
     * 消息内容
     */
    private String msg = "";

    /**
     * 返回的数据对象
     */
    private T data;

    /**
     * 失败时的错误码
     */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String errCode;

    public ReturnObject(T data) {
        this.data = data;
    }

    public static ReturnObject<Void> success(){
        return new ReturnObject<>();
    }

    public static <T> ReturnObject<T> success(T data){
        return new ReturnObject<>(data);
    }
}
